package com.hdl.servlet.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.service.UserService;
import com.hdl.service.impl.UserServiceImpl;

/**
 * CheckNameServlet 异步校验用户名
 * @author Administrator
 *
 */
@WebServlet("/check-name.let")
public class CheckNameServlet extends HttpServlet{
	
	private UserService service = new UserServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取参数
		String userName = req.getParameter("hdlUserName");
		
		//调用业务逻辑方法
		boolean flag = service.checkName(userName);
		resp.setContentType("text/json;charset=UTF-8");
		resp.getWriter().print("{\"valid\":"+flag+"}");
		resp.flushBuffer();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

}
